<?php

/*
 * dragon.hu 2015.6.13 add 数值数据采集
*/
defined('BASEPATH') or die('forbidden');

class FbdataAnalysis_Controller extends Controller
{
	private $dbConn;
	private $nameList;
	private $fbnameList;
	private $fbtypeList;
	
	function _init()
	{
		check_level(50, segment(0), segment(1));
		set_time_limit(0);
		
		$areanum = $_SESSION['area_selected_id'];
		if ($areanum == '')
		{
			echo "<script>alert('" . translate('C_SELECT_AREA_TEXT') . "');</script>";
			return;
		}
		//不用这个，因为没有连接到gm库
		$this->dbConn = getTmpDbConnect(PLATFORM_ALL, 'all', $areanum, DBTYPE_GAMESERVER);
		$sql = "SELECT id, name from player";
		$this->dbConn->query($sql);
		while ($n = $this->dbConn->get_array('default')){
			$this->nameList[$n['id']] = trim($n['name']);
		}
		$this->dbConn->free_all();
		
		$this->fbnameList = get_type_fbname();
		//print_r($this->fbnameList);
		//exit(0);
		$this->fbtypeList = get_type_fbtype();
	}
	
	function flexigrid()
	{
		list ( $colkey, $colsinfo, $where, $sortname, $sortorder, $offset, $rp, $page ) = $this->common->get_flexigrid_params ();
		
		$areanum = $_SESSION['area_selected_id'];
		$sql = "SELECT COUNT(id) AS num FROM tt_playerfbdata WHERE serverid = '$areanum'";
		//print_r($areanum);
		//print_r($sql);
		//exit(0);
		$one = $this->db->one ( $sql );
		$total = $one ['num'];
		//print_r($one);
		//echo "++";
		//print_r($page);
		//echo "--";
		//print_r(total);
		$orderby = $sortname ? "ORDER BY {$sortname} {$sortorder} " : "";
		//print_r($orderby);
		//exit(0);
		
		$sql = "SELECT {$colsinfo} FROM tt_playerfbdata WHERE serverid = '$areanum' {$orderby} LIMIT {$offset},{$rp}";
		$this->db->query ( $sql );
		while ( $n = $this->db->get_array () ) {
			$n['roleid'] = $this->nameList[$n ['roleid']]."-".$n['roleid'];
			$n['fbid'] = $this->fbnameList[$n['fbid']]."-".$n['fbid'];
			$n['fbtype'] = $this->fbtypeList[$n['fbtype']]."-".$n['fbtype'];
			
			$row [] = array (
					'id' => $n ['id'],
					'cell' => $n
			);
		}
		$result = array (
				'page' => $page,
				'total' => $total,
				'rows' => $row
		);
		echo json_encode ( $result );
		
		/*
		list($colkey, $colsinfo, $where, $sortname, $sortorder, $offset, $rp, $page) = $this->common->get_flexigrid_params();
		
		//$this->db->connect('111.75.194.177','root','654321');
		//200090016 表示 充值
		$sql = "SELECT COUNT(*) AS num FROM tt_playerfbdata as A where serverid = '$areanum'";
		//echo " sql2:$sql ";
		$one = $this->dbConnt->one($sql);
		$total = $one['num'];
		$orderby = $sortname ? "ORDER BY {$sortname} {$sortorder} " : "";
		
		$sql = "SELECT {$colsinfo} FROM tt_playerfbdata where serverid = '$areanum'  {$orderby} LIMIT {$offset},{$rp}";
		$this->dbConnt->query($sql);
		//$id = 0;
		while ($n = $this->dbConnt->get_array('default')) {
		
			//$n['profession']=$this->professionList[$n['profession']]."(".$n['profession'].")";
			//$n['profession_type']=$this->professionList[$n['profession_type']]."(".$n['profession_type'].")";
			//$n['indate']=get_datetime($n['indate']);
			$rows[] = array('id' => $n['id'], 'cell' => $n);
			//$id = $id+1;
		}
		//var_dump($rows);
		$result = array(
				'page' => $page,
				'total' => $total,
				'rows' => $rows
		);
		
		//$this->dbConnt->free_all();
		echo json_encode($result);*/
	}
	
	function index()
	{
		$this->view->display("message/fbdataAnalysis/index");
	}
	
}